const log4js = require('log4js');

log4js.configure({
  appenders: {
    out: {type: 'stdout'},
    //所有日志记录，文件类型file   文件最大值maxLogSize 单位byte (B->KB->M) backups:备份的文件个数最大值,最新数据覆盖旧数据
    //allLog: { type: 'file', filename: './logs/all.log', keepFileExt: true, maxLogSize: 10485760, backups: 5 },
    //http请求日志  http请求日志需要app.use引用一下， 这样才会自动记录每次的请求信息 
    //httpLog: { type: "dateFile", filename: "./logs/httpAccess.log", pattern: ".yyyy-MM-dd", keepFileExt: true },
    //错误日志 type:过滤类型logLevelFilter,将过滤error日志写进指定文件
    errorLog: { type: 'file', filename: './logs/error.log' },
    //数据库Log
    dbLog:{ type: 'file', filename: './logs/db.log', level: "info", maxLogSize: 10485760, backups: 5 },
    error: { type: "logLevelFilter", level: "error", appender: 'errorLog' }
},
categories: {
    //appenders:采用的appender,取上面appenders项,level:设置级别
    //http: { appenders: ['out', 'httpLog'], level: "debug" },
    dbLog: { appenders: ['out', 'dbLog'], level: "info" },
    default: { appenders: ['out', 'error'], level: 'debug' }, //error写入时是经过筛选后留下的
}
});
// const logger = log4js.getLogger("api-servers");
// const httpLog = log4js.getLogger('http');
// const httpLogger = log4js.connectLogger(httpLog, { level: 'WARN' });
const dbLog = log4js.getLogger('dbLog');

module.exports = {
  log4js, dbLog
}